package main

import (
	"fmt"
	"time"
)

func main() {

	c := make(map[string]int)
	go func() { //开一个协程写map
		for j := 0; j < 10000; j++ {
			c[fmt.Sprintf("%d", j)] = j
		}
	}()

	// todo fatal error: concurrent map writes
	//go func() { //开一个协程写map
	//	for j := 10000; j < 20000; j++ {
	//		c[fmt.Sprintf("%d", j)] = j
	//	}
	//}()


	// todo fatal error: concurrent map read and map write
	for j := 0; j < 10000; j++ {
		go func() { //开一个协程读map

			fmt.Println(c[fmt.Sprintf("%d", j)])
		}()
	}

	time.Sleep(time.Second * 20)

}
